<?php

/**
 * @Author: kendy
 * @Date:   2019-12-24 08:58:45
 * @Last Modified by:   jiayanting
 * @Last Modified time: 2019-12-24 11:08:42
 * 商家结算控制器
 */
namespace app\hotel\controller;

use app\hotel\model\Order as orderModel;
use think\Db;
use think\Request;
use think\Session;

class Settlements extends Common
{

      /**
       * [index 结算订单列表]
       * @Author   kendy
       * @DateTime 2019-12-24T09:16:01+0800
       * @return   [type]                   [description]
       */
      static function unsettledquery()
      {  

        if (Request::instance()->isAjax()) { 
            $get = Request::instance()->get(); 
            $where = [];
    	  
            if (isset($get['order_sn']) && $get['order_sn'] != '') {
               $where['order_sn'] = ['like','%'.input('order_sn').'%'];
            }

            $count = model('Settlements')->getUnSettledList($where, 0, 0, true);

            $pagesize = (int)$get['limit'];
            $page = (int)$get['page']; 
            if ($page == 1) {
                $startrow = 0;
            } else {
                $startrow = ($page - 1) * $pagesize;
            }

            $data = model('Settlements')->getUnSettledList($where, $startrow, $pagesize, false);

            return ['code' => 0, 'msg' => '', 'count' => $count, 'data' => $data];

        } else {  
            return view();
        }

      }

      /**
       * [settledquery 已结算订单列表]
       * @Author   kendy
       * @DateTime 2019-12-24T10:58:23+0800
       * @return   [type]                   [description]
       */
      public function settledquery()
      {
      	 if (Request::instance()->isAjax()) { 
            $get = Request::instance()->get(); 
            $where = [];
    	  
            if (isset($get['order_sn']) && $get['order_sn'] != '') {
               $where['order_sn'] = ['like','%'.input('order_sn').'%'];
            }

            $count = model('Settlements')->getSettledList($where, 0, 0, true);

            $pagesize = (int)$get['limit'];
            $page = (int)$get['page']; 
            if ($page == 1) {
                $startrow = 0;
            } else {
                $startrow = ($page - 1) * $pagesize;
            }

            $data = model('Settlements')->getSettledList($where, $startrow, $pagesize, false);

            return ['code' => 0, 'msg' => '', 'count' => $count, 'data' => $data];

        } else {  
            return view();
        }

      }

    /*
     * 银行卡信息
     */
    public function bank()
    {
         if (Request::instance()->isAjax()){
            $where['is_del'] = array('eq',0);
            $data = Db::name('hotel')->where('hotel_id',Session::get('hotel_id'))->where($where)->select();
            if(empty($data[0]['hotel_bank_card'])){
                 return ['code'=>0,'msg'=>'','data'=>''];
            }else{
                return ['code'=>0,'msg'=>'','data'=>$data];
            }
            
        }else{
           //获取景区信息
            $team = Db::name('hotel')->where('hotel_id',Session::get('hotel_id'))->find();
            $this->assign('team',$team);

            return view();
        }
        
    }

     //添加银行卡
    public function addBank()
    {
        if(Request::instance()->isPost()){
            $post = Request::instance()->post();
            $post = $post['data'];
            $data = [
                'hotel_bank_card'=>$post['hotel_bank_card'],
                'hotel_bank_name'=>$post['hotel_bank_name'],
                'bank_user_name'=>$post['bank_user_name'],
            ];
            $res = Db::name('hotel')->where('hotel_id',Session::get('hotel_id'))->update($data);
            if ($res){
        
                return ['code'=>0];

            }else{
                return ['code'=>'添加失败'];
            }
        }
    }

    //修改银行卡
    public function editBank()
    {
        if(Request::instance()->isPost()){
            $post = Request::instance()->post();
            $post = $post['data'];
            $data = [
                'hotel_bank_card'=>$post['hotel_bank_card'],
                'hotel_bank_name'=>$post['hotel_bank_name'],
                'bank_user_name'=>$post['bank_user_name'],
            ];
            $res = Db::name('hotel')->where('hotel_id',Session::get('hotel_id'))->update($data);
            if ($res){
        
                return ['code'=>0];

            }else{
                return ['code'=>'添加失败'];
            }
        }
    }


}